package cn.xiaopengstack.domain.activity.repository;

import cn.xiaopengstack.domain.activity.model.aggregate.CreatePartakeOrderAggregate;
import cn.xiaopengstack.domain.activity.model.aggregate.CreateRechangeQuotaOrderAggregate;
import cn.xiaopengstack.domain.activity.model.entity.*;
import cn.xiaopengstack.domain.activity.model.valobj.ActivitySkuStockKeyVO;

import java.util.List;

/**
 * @author jiangyangang
 */
public interface IRaffleActivityRepository {

    /**
     * 查询抽奖活动信息
     * @param activityId
     * @return
     */
    RaffleActivityEntity queryRaffleActivityByActivityId(Long activityId);

    /**
     * 查询抽奖活动sku
     * @param activitySkuId
     * @return
     */
    RaffleActivitySkuEntity queryActivitySku(Long activitySkuId);

    /**
     * 查询活动次数配置
     * @param countId
     * @return
     */
    RaffleActivityCountEntity queryRaffleActivityCountByActivityCountId(Long countId);

    /**
     * 查询活动账户
     * @param activity
     * @param userId
     * @return
     */
    RaffleActivityAccountEntity queryActivityAccount(Long activity, String userId);

    /**
     * 保存活动订单
     * @param createOrderAggregate
     */
    void saveNoPayOrder(CreateRechangeQuotaOrderAggregate createOrderAggregate);

    /**
     * 保存积分兑换订单
     * @param createOrderAggregate
     */
    void saveCreditExchangeOrder(CreateRechangeQuotaOrderAggregate createOrderAggregate);
    /**
     * 缓存SKU库存
     * @param skuId
     * @param stockCount
     * @return
     */
    void cacheActivitySkuStockCount(Long skuId, Integer stockCount);

    /**
     * 扣减活动SKU库存
     *
     * @param stockKeyVO
     * @return
     */
    boolean subtractionActivitySkuStock(ActivitySkuStockKeyVO stockKeyVO);

    /**
     * 推送库存扣减动作的延迟队列
     * @param stockKeyVO
     */
    void produceActivitySkuStockDecrQueue(ActivitySkuStockKeyVO stockKeyVO);

    /**
     * 消费延迟队列里的扣减库存
     * @return
     */
    ActivitySkuStockKeyVO consumeActivitySkuStockDecrQueue() throws InterruptedException;

    /**
     * 清空队列
     */
    void clearActivitySkuStockDecrQueue(ActivitySkuStockKeyVO stockKeyVO);

    /**
     * 递减更新SKU库存
     * @param skuId
     * @param decrNumber
     */
    void updateActivitySkuStock(Long skuId, Integer decrNumber);

    /**
     * 清空SKU库存
     * @param skuId
     */
    void clearActivitySkuStock(Long skuId);

    /**
     * 查询sku缓存
     * @param sku
     * @return
     */
    Integer queryActivitySkuStockCache(Long sku);

    /**
     * 保存用户抽奖订单
     * @param orderAggregate
     */
    void saveUserRafflePartakeOrder(CreatePartakeOrderAggregate orderAggregate);

    /**
     * 查询总账户
     * @param userId
     * @param activityId
     * @return
     */
    RaffleActivityAccountEntity queryActivityAccountByUserId(String userId, Long activityId);

    /**
     * 查询月账户
     * @param userId
     * @param activityId
     * @param month
     * @return
     */
    ActivityAccountMonthEntity queryActivityAccountMonthByUserId(String userId, Long activityId, String month);

    /**
     * 查询日账户
     * @param userId
     * @param activityId
     * @param day
     * @return
     */
    ActivityAccountDayEntity queryActivityAccountDayByUserId(String userId, Long activityId, String day);

    /**
     * 查询未使用的抽奖单
     * @param activityId
     * @param userId
     * @return
     */
    UserRaffleOrderEntity queryRaffleActivityUnusedPartakeOrderByUid(Long activityId, String userId);

    /**
     * 查询SKU信息
     * @param activityId
     * @return
     */
    List<RaffleActivitySkuEntity> queryActivitySkuByActivityId(Long activityId);

    /**
     * 更新加
     * @param rechangeTradeResult
     */
    void updateTradeOrder(RechangeTradeResultEntity rechangeTradeResult);

    /**
     * 查询SKU信息
     * @param activityId
     * @return
     */
    List<SkuProductEntity> querySkuProducts(Long activityId);
}
